package com.example.crm.servlet;

import com.example.crm.pojo.Customer;
import com.example.crm.service.ICustomerService;
import com.example.crm.service.impl.CustomerServicelmpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

@WebServlet("/customer/updatecheck")
public class CustomerUpdateCheckServlet extends HttpServlet {

    ICustomerService customerService = new CustomerServicelmpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        Customer customer=new Customer();
        try {
            BeanUtils.populate(customer,req.getParameterMap());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        customerService.update(customer);


        req.getRequestDispatcher("/customer").forward(req,resp);
    }
}
